//! @Author: DengLibin
//! @Date: Create in 2023-11-06 17:34:15
//! @Description: 





use serde::{Deserialize, Serialize};

use super::global::{to_global_result, GlobalResult};




///配置属性
#[derive(Debug, Serialize, Deserialize)]
pub struct AppConfig {
   pub port: u16, //端口
   pub pg_url: String, //db连接
   pub mysql_url: String, //db连接
   pub max_conn: u32, //连接池最大连接数
}



/// @Author: DengLibin
/// @Date: Create in 2023-11-01 16:21:13
/// @Description: 读取文件配置
pub fn read_yaml_config(file_path: &str) -> GlobalResult<AppConfig> {
    // 使用相对路径读取 app.yaml 内容为字符串
    // let yaml_str = read_file_str(file_path)?;
    let  file = to_global_result(std::fs::File::open(file_path))?;
    // serde_yaml 解析字符串为 User 对象
    let config: AppConfig = to_global_result(serde_yaml::from_reader(file))?;
    return Ok(config);
}
